import { AxiosRequestConfig, AxiosStatic } from './types/index'
import { Axios } from './core/axios'
import { extend } from './helpers/util'
import defaults from './defaults'
import mergeConfig from './core/mergeConfig'
function createInstance(config: AxiosRequestConfig): AxiosStatic {
  let context = new Axios(config)
  let instance = Axios.prototype.request.bind(context)

  extend(instance, context)
  return instance as AxiosStatic
}

let axios = createInstance(defaults)

axios.create = function create(config?: AxiosRequestConfig) {
  return createInstance(mergeConfig(defaults, config))
}

export default axios
